package com.hmdp.consumer;

import cn.hutool.json.JSONUtil;
import com.hmdp.entity.VoucherOrder;
import com.hmdp.service.IVoucherOrderService;
import com.hmdp.service.impl.VoucherOrderServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RabbitMQConsumer {
    @Resource
    VoucherOrderServiceImpl voucherOrderService;
    @RabbitListener(queues = "VoucherOrder.queue")
    public void listenSimpleQueueMessage(String msg){
        // 1.从msg中解析出调用生产订单信息的参数实体
        VoucherOrder voucherOrder = JSONUtil.toBean(msg, VoucherOrder.class);
        // 2.调用生成订单的接口
        System.out.println("spring 消费者接收到消息：【" + voucherOrder + "】");
        voucherOrderService.handleVoucherOrder(voucherOrder);
    }
}
